package com.itgacl.magic4j.modules.mp.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信支付相关配置
 *
 * @author zhongzhq
 * @date 2021/6/24 0024
 */
@Configuration
public class WxPayConfiguration {

    @Autowired
    private WxMpConfig wxMpConfig;

    @Bean
    public WxPayConfig payConfig() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(wxMpConfig.getAppId());
        payConfig.setMchId(wxMpConfig.getMchId());
        payConfig.setMchKey(wxMpConfig.getMchKey());
        payConfig.setSubAppId(wxMpConfig.getSubAppId());
        payConfig.setSubMchId(wxMpConfig.getSubMchId());
        payConfig.setKeyPath(wxMpConfig.getKeyPath());
        payConfig.setPrivateKeyPath(wxMpConfig.getPrivateKeyPath());
        payConfig.setPrivateCertPath(wxMpConfig.getPrivateCertPath());
        payConfig.setApiV3Key(wxMpConfig.getApiV3Key());
        payConfig.setCertSerialNo(wxMpConfig.getCertSerialNo());
        payConfig.setServiceId(wxMpConfig.getServiceId());
        return payConfig;
    }

    @Bean
    public WxPayService payService() {
        WxPayService payService = new WxPayServiceImpl();
        payService.setConfig(payConfig());
        return payService;
    }

}
